﻿<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <!--_meta 作为公共模版分离出去-->
    <% layout("/common/_meta.html",{title:"添加角色"}){} %>
    <!--_meta 作为公共模版分离出去-->
</head>
<body style="background-color:#fff">
<div class="wap-container">
    <div class="panel">
        <div class="panel-body">
            <form action="${ctxPath}/role/add" method="post" class="form form-horizontal" id="form-role-add">
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>角色名称：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <input type="text" class="input-text" value="${role.name!}" placeholder="角色名称" id="name" name="name">
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3">说明：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <textarea id="description" name="description" cols="" rows="" class="textarea"  placeholder="角色说明">${role.description!}</textarea>
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3">权限配置：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <%for(top in tops){%>
                        <dl class="Hui-admin-permission-list">
                            <dt>
                                <label>
                                    <input type="checkbox" value="${top.id}" name="permissionIds" id="user-Character-${top.id}">${top.name}
                                </label>
                            </dt>
                            <dd>
                                <%for(sec in top.children){%>
                                <dl class="cl Hui-admin-permission-list2">
                                    <dt>
                                        <label class="">
                                            <input type="checkbox" value="${sec.id}" name="permissionIds" id="user-Character-${top.id}-${sec.id}">${sec.name}
                                        </label>
                                    </dt>
                                    <dd>
                                        <%for(thd in sec.children){%>
                                        <label class="">
                                            <input type="checkbox" value="${thd.id}" name="permissionIds" id="user-Character-${top.id}-${sec.id}-${thd.id}">${thd.name}
                                        </label>
                                        <%}%>
                                    </dd>
                                </dl>
                                <%}%>
                            </dd>
                        </dl>
                        <%}%>
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-xs-8 col-sm-8 col-xs-offset-3 col-sm-offset-3">
                        <button type="submit" class="btn btn-success btn-block radius">添加角色</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<% layout("/common/_footer.html"){} %>
<% layout("/common/_validate.html"){} %>
<!--/_footer 作为公共模版分离出去-->
<script type="text/javascript">
    $(function(){

        $(".Hui-admin-permission-list dt input:checkbox").click(function(){
            $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
        });
        $(".Hui-admin-permission-list2 dd input:checkbox").click(function(){
            var l =$(this).parent().parent().find("input:checked").length;
            var l2=$(this).parents(".Hui-admin-permission-list").find(".Hui-admin-permission-list2 dd").find("input:checked").length;
            if($(this).prop("checked")){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
                $(this).parents(".Hui-admin-permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
            }
            else{
                if(l==0){
                    $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
                }
                if(l2==0){
                    $(this).parents(".Hui-admin-permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
                }
            }
        });

        $("#form-role-add").validate({
            rules:{
                name:{
                    required:true,
                    maxlength:50
                },
                description:{
                    maxlength:255
                },
            },
            submitHandler:function(form){
                loading();
                form.submit();
            }
        });
    });
</script>
</body>
</html>
